﻿using EmbeddedSharp.Core;

namespace Zove.Runtime.Core.Zoom
{
    /// <summary>
    /// Zoom language nature
    /// </summary>
    public class ZoomLanguageNature : ILanguageNature
    {

        protected ZoomClassFinder ZoomClassFinder;

        protected ZoomClassParserFactory ZoomClassParserFactory;

        protected DefaultRuntimeModelLoader DefaultRuntimeModelLoader;

        #region ILanguageNature Members

        /// <summary>
        /// Class finder
        /// </summary>
        public IClassFinder ClassFinder
        {
            get
            {
                if (ZoomClassFinder == null)
                {
                    ZoomClassFinder = new ZoomClassFinder();
                }

                return ZoomClassFinder;
            }
        }

        /// <summary>
        /// Class parser factory
        /// </summary>
        public IClassParserFactory ClassParserFactory
        {
            get
            {
                if (ZoomClassParserFactory == null)
                {
                    ZoomClassParserFactory = new ZoomClassParserFactory(this);
                }
                return ZoomClassParserFactory;
            }
        }

        /// <summary>
        /// Atomic type, which is factor
        /// </summary>
        public string[] AtomicTypes
        {
            get
            {
                return new []
                           {
                               "factor"
                           };
            }
        }

        public IRuntimeModelLoader ModelLoader
        {
            get
            {
                if (DefaultRuntimeModelLoader == null)
                {
                    DefaultRuntimeModelLoader = new DefaultRuntimeModelLoader(this);
                    DefaultRuntimeModelLoader.ClassLoader = ClassLoader;
                }

                return DefaultRuntimeModelLoader;
            }
        }

        protected DefaultClassLoader DefaultClassLoader;

        public IClassLoader ClassLoader
        {
            get
            {
                if (DefaultClassLoader == null)
                {
                    DefaultClassLoader = new DefaultClassLoader(this);
                }

                return DefaultClassLoader;
            }
        }

        protected ZoomFunctionManager ZoomFunctionManager;

        public IFunctionManager FunctionManager
        {
            get
            {
                if (ZoomFunctionManager == null)
                {
                    ZoomFunctionManager = new ZoomFunctionManager(this);
                }

                return ZoomFunctionManager;
            }
        }

        protected ZoomExpressionParserFactory ZoomExpressionParserFactory;

        public IExpressionParserFactory ExpressionParserFactory
        {
            get
            {
                if (ZoomExpressionParserFactory == null)
                {
                    ZoomExpressionParserFactory = new ZoomExpressionParserFactory(this);
                }
                return ZoomExpressionParserFactory;
            }
        }

        protected DefaultExpressionTranslator DefaultExpressionTranslator;

        public IExpressionTranslator ExpressionTranslator
        {
            get { return DefaultExpressionTranslator ?? (DefaultExpressionTranslator = new DefaultExpressionTranslator()); }
        }

        #endregion
    }
}